/**
 * @Author Stringzhua
 * @Date 2024/11/30 13:42
 * description:
 */
public class demo02 {
    public static void main(String[] args) {
        String s = "i am a cool boy";
        //请你写一个方法返回长度最长的单词的长度
        System.out.println(getMaxLength(s));
    }

    public static int getMaxLength(String s) {
        //这里不能使用split方法
//        String[] array = s.split(" ");
        if (s == null || s.isEmpty()) {
            return 0;
        }
        int max = 0;
        int currentLength = 0;

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == ' ') {
                max = Math.max(max, currentLength);
                currentLength = 0;
            } else {
                currentLength++;
            }
        }
        return Math.max(max, currentLength);
    }
}
